﻿using System;

namespace HashFoo.Rest.Common
{
    /// <summary>
    /// Handles serialization of objects on the client.
    /// </summary>
    public interface IResourceSerializer
    {
        /// <summary>
        /// Reads an object from a string.
        /// </summary>
        /// <typeparam name="T">The type of object to be returned</typeparam>
        /// <param name="data">The string data to deserialize into the object</param>
        /// <returns>The deserialized object.</returns>
        T Read<T>(string data);

        /// <summary>
        /// REads an object from as string.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        object Read(string data, Type type);

        /// <summary>
        /// Write an object to a serialized string.
        /// </summary>
        /// <typeparam name="T">The type of object to serialize.</typeparam>
        /// <param name="data">The data to serialize.</param>
        /// <returns>The serialized data string.</returns>
        string Write<T>(T data);


        /* These serialization meta data properties may be better situated in
         * the definition with the models/resources of the application.
         * Possibly could map IResourceSerializer types to a set of serialization meta data.
         * 
         * For now, I think its not too big of a smell to put them here, though, as it is not
         * completely unreasonable to expect a serializer to know its MIME types. 
         * 
         * DMF 2011-09-21 */

        /// <summary>
        /// The MIME types this serializer will accept
        /// </summary>
        string[] AcceptMimeTypes { get; }

        /// <summary>
        /// The MIME type to which content is serialized.
        /// </summary>
        string ContentMimeType { get; }
    }
}